var myDB = require('../lib/myDB');


//测试一:多行sql语句,不带参数
function test1(fn) {
    var sql1 = 'drop table if exists user;';
    var sql2 = 'create table user(id integer auto_increment primary key ,name varchar(255),age int ,intro text);';
    var sql3 = 'insert into user (name,age,intro) values("wang",11,"wangIntro");';
    var sql4 = 'select * from user;';
    var sqls = sql1 + sql2 + sql3 + sql4;
    myDB.exeSqls(undefined, sqls, '', function (err, data) {
        console.log(err, data);
        fn();
    })
}


//测试三:一行语句,带一行参数
function test2(fn) {
    var sql4 = 'select * from user;';
    var sql = 'insert into user (name,age,intro) values(?,?,?)';
    var pm = ['zhao', 22, 'zhaoIntro'];
    myDB.exeSqls(undefined, sql, pm, function (err, data) {
        console.log(err, data);
        myDB.exeSqls(undefined, sql4, null, function (err, data) {
            console.log(err, data);
            fn();
        })
    })
}


//测试三:一行语句,带多行参数
function test3(fn) {
    var sql4 = 'select * from user;';
    var sql = 'insert into user (name,age,intro) values(?,?,?)';
    var pms = [
        ['zhang', 33, 'zhangIntro'],
        ['li', 44, 'liIntro']
    ];
    myDB.exeSqls(undefined, sql, pms, function (err, data) {
        console.log(err, data);
        myDB.exeSqls(undefined, sql4, null, function (err, data) {
            console.log(err, data);
            fn();
        })
    })
}

function main() {
//    test1(function () {
//        test2(function () {
//            test3(function () {
//            });
//        })
//    })


    var sql = 'select  *  from user where id in(?,?,?) order by id desc limit  0 , 10 ';
    myDB.exeSqls(undefined, sql, ['1','2','3'], function (err, data) {
        console.log(err, data);
    })

}
main();